package com.web.expspringboot.controller;

import com.web.expspringboot.entity.UserSt;
import com.web.expspringboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sign")
public class UserController {

    @Autowired
    UserService us;

    //发送验证码
    @PostMapping("/getPhoneCode")   //注册0 重设密码1
    public boolean getPhoneCode(@RequestParam("phoneNum") String phoneNum, @RequestParam("mode") int mode){return us.getPhoneCode(phoneNum, mode);}

    //登录
    @PostMapping("/signInCheck") //0成功 1未注册 2密码错误 3被封禁
    public int signInCheck(@RequestParam("phoneNum") String phoneNum, @RequestParam("password") String password){return us.signInCheck(phoneNum, password);}

    //注册
    @PostMapping("/signUp") //0成功 1已注册 2验证码错误
    public int signIn(@RequestParam("phoneNum") String phoneNum, @RequestParam("code") String code, @RequestParam("password") String password){return us.signUp(phoneNum, code, password);}

    //修改密码
    @PostMapping("/resetPassword")  //0成功 1未注册 2验证码错误
    public int resetPassword(@RequestParam("phoneNum") String phoneNum, @RequestParam("code") String code, @RequestParam("newPassword") String newPassword){return us.resetPassword(phoneNum, code, newPassword);}

    //查询是否是管理员
    @GetMapping("isManager")
    public boolean getIsManager(@RequestParam("phoneNum") String phoneNum){
        return us.getIsManager(phoneNum);
    }

    //查询所有用户
    @GetMapping("allUser")
    public List<UserSt> getAllUser(){
        return us.getAllUser();
    }

    //更改一条用户信息
    @PostMapping("updateOneUser")
    public boolean updateOneUser(@RequestBody UserSt user){
        return us.updateOneUser(user);
    }

    //测试user session
    @GetMapping("testSession")
    public long testSession(){
        return us.getSessionUserId();
    }

}
